﻿public partial class Solution
{
    public int Reverse(int x)
    {
        int result = 0;
        while (x != 0)
        {
            if (result >= int.MinValue / 10 && result <= int.MaxValue / 10)
            {
                int digit = x % 10;
                x /= 10;
                result = result * 10 + digit;
            }
            else
            {
                result = 0;
                break;
            }
        }
        return result;
    }
}
